package com.lixin.smartclassroom.ui.home.tab4.activity

import com.drake.brv.utils.bindingAdapter
import com.drake.channel.receiveEvent
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.yanxuegrouplist
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.common.commonEditTextDialog
import com.lixin.smartclassroom.databinding.ActivitySetGroupBinding
import com.lixin.smartclassroom.ui.home.adapter.setGroup
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.visible

/**
 * Description 设置分组
 * Author: lwc
 * Date:2023/12/12 11:46
 */
class SetGroupAct : BaseActivity<ActivitySetGroupBinding>() {
    override fun getViewBinding() = ActivitySetGroupBinding.inflate(layoutInflater)

    override fun topBarHide() = false
    override fun startPadding() = true
    private lateinit var listBean: ArrayList<DataListBean>
    private lateinit var listBeanAdd: ArrayList<DataListBean>
    override fun title() = "设置分组"
    override fun textMenuContent() = "新建分组"
    private var courseid = ""

    override fun onTextMenuListener() {
        commonEditTextDialog(3, courseid, "创建分组", "请输入分组名称", "取消", "确定", onSure = {
            listBeanAdd = ArrayList()
            listBeanAdd.add(DataListBean())
            listBean.addAll(listBeanAdd)
            binding.refresh.autoRefresh()
        })
    }


    override fun iniView() {
        listBean = ArrayList()
        courseid = getIntentString("courseid")
        binding.recycler.setGroup(courseid)

        getGroupListData()

        receiveEvent<String>("refreshGroupList") {
            binding.refresh.refresh()
        }
    }



    private fun getGroupListData() {
        binding.apply {
            refresh.onRefresh {
                scopeNetLife {
                    listBean = yanxuegrouplist(courseid, 1, 100)!!
                    addData(listBean) {
                        if (binding.recycler.bindingAdapter.models?.size == 0) {
                            binding.state.showEmpty()
                            binding.recycler.gone()
                        } else {
                            binding.recycler.visible()
                        }
                        listBean.size == 100
                    }
                }
            }.autoRefresh()
        }
    }

    override fun onClick() {

    }

}